/*
**********************************************************************************
    OpenSURF642 : An TI DM642 implementation of OpenSURF.
    Copyright (C) 2011  Hai Yu

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
    
	This implementation is based on The original OpenSURF library created
	by Christopher Evans.The original work can be found at
		http://www.chrisevansdev.com/computer-vision-opensurf.html
	
    contact: yuhaihai12345@gmail.com	
**********************************************************************************
*/


#include "MatrixMultiply.h"
#include <assert.h>
#include "fastrts62x64x.h"


void MatrixMultiplyDouble(  double * a, int a_rows, int a_columns, 
                            double * b, int b_rows, int b_columns, 
                            double * c)
{
    int c_rows = a_rows, c_columns = b_columns;
    int i,j,k;
    double sum;
    
    assert(a_columns == b_rows);
    for(i = 0; i < c_rows; i++)
    {
        for(j = 0; j < c_columns; j++)
        {
            sum = 0;
            for(k = 0; k < a_columns; k++)
            {
                sum = sum + a[i*a_columns + k] * b[k * b_columns + j];                
            }
            c[i*c_columns + j] = sum;
        }
    }
    
}



void MatrixMultiplyFloat (  float * a, int a_rows, int a_columns, 
                            float * b, int b_rows, int b_columns, 
                            float * c)
{
    int c_rows = a_rows, c_columns = b_columns;
    int i,j,k;
    float sum;
    
    assert(a_columns == b_rows);
    for(i = 0; i < c_rows; i++)
    {
        for(j = 0; j < c_columns; j++)
        {
            sum = 0;
            for(k = 0; k < a_columns; k++)
            {
                sum = addsp(sum, mpysp(a[i*a_columns + k] , b[k * b_columns + j]));                
            }
            c[i*c_columns + j] = sum;
        }
    }
    
}

